package com.emm.yixun.mobile.adapter;

import java.util.ArrayList;

import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.model.MenuList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * <p>
 * <b>Title：</b>分析列表菜单适配器
 * </p>
 * <p>
 * <b>Description：</b>
 * </p>
 * 
 * 
 * @author tangxin
 * @date 2017年1月5日 下午12:59:17
 */
public class AnalysisMenuAdapter extends BaseAdapter {

	ArrayList<MenuList> menulist;
	Activity a;

	public AnalysisMenuAdapter(ArrayList<MenuList> menulist, Activity a) {
		this.menulist = menulist;
		this.a = a;
	}

	/**
	 * <p>
	 * <b>Title：</b> 设置数据刷新
	 * </p>
	 * <p>
	 * <b>Description：</b>
	 * </p>
	 * 
	 * @author tangxin
	 * @date 2017年1月5日 下午2:17:48
	 */
	public void Setdata(ArrayList<MenuList> menulist) {
		this.menulist = menulist;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return null == menulist ? 0 : menulist.size();
	}

	@Override
	public Object getItem(int position) {
		return null == menulist ? null : menulist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHoudlerMenu v = null;
		if (null == convertView) {
			convertView = LayoutInflater.from(a).inflate(R.layout.analysis_menu_item, null);
			v = new ViewHoudlerMenu();
			v.menu_img = (ImageView) convertView.findViewById(R.id.menu_img);
			v.menu_title = (TextView) convertView.findViewById(R.id.menu_title);
			convertView.setTag(v);
		} else {
			v = (ViewHoudlerMenu) convertView.getTag();
		}

		v.menu_img.setImageResource(menulist.get(position).getImg_id());
		v.menu_title.setText(menulist.get(position).getTitle());

		return convertView;
	}

	public static class ViewHoudlerMenu {
		ImageView menu_img;
		TextView menu_title;
	}

}
